package com.kaoshi.management.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kaoshi.common.config.Result;
import com.kaoshi.management.pojo.XtSettingsDrug;
import com.kaoshi.management.service.XtSettingsDrugService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-10-30
 */
@RestController
@CrossOrigin
@RequestMapping("/settings-drug")
public class XtSettingsDrugController {
    @Autowired
    private XtSettingsDrugService xtSettingsDrugService;

    @PostMapping("/cc/{current}/{pageSize}")
    public Result findAll(@PathVariable Integer current, @PathVariable Integer pageSize,
                          @RequestBody XtSettingsDrug SettingsDrug){
        Page<XtSettingsDrug> page = xtSettingsDrugService.findAll(current, pageSize, SettingsDrug);
        return Result.ok(page);
    }

    @PostMapping("/change")
    public Result add(@RequestBody XtSettingsDrug SettingsDrug){
        if(SettingsDrug.getId() == null){
            SettingsDrug.setStatus(0);
            SettingsDrug.setPublisher("李明明");
            LocalDate localDate= LocalDate.now();
            SettingsDrug.setOperationTime(localDate.atStartOfDay());
            xtSettingsDrugService.save(SettingsDrug);
            return Result.ok("添加成功");
        }else{
            xtSettingsDrugService.updateById(SettingsDrug);
            return Result.ok("修改成功");
        }
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        xtSettingsDrugService.removeById(id);
        return Result.ok("删除成功");
    }

    //    @DeleteMapping("delete/{id}")
//    public Result delete(@PathVariable Integer id) {
//        // 获取要删除的实体
//        XtManagement xtManagement = xtManagementService.getById(id);
//        if (xtManagement != null) {
//            // 设置为逻辑删除状态
//            xtManagement.setLjdelete(1);
//            xtManagementService.updateById(xtManagement); // 更新记录
//        }
//        return Result.ok("删除成功");
//    }





}
